package com.loan.market.util

import android.app.Activity
import android.app.Dialog
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import com.loan.market.R

fun Activity.showDialog(
    view: View,
    fillWidth: Boolean = false,
    fillHeight: Boolean = false,
    position: Int = Gravity.CENTER
): Dialog {
    val dialog = Dialog(this, R.style.NormalDialog)
    dialog.setContentView(view)
    dialog.show()
    dialog.window?.attributes = dialog.window?.attributes?.apply {
        gravity = position
        width = if (fillWidth) WindowManager.LayoutParams.MATCH_PARENT else (getScreenWidth() * 0.9).toInt()
        if (fillHeight) {
            height = (getScreenHeight() * 0.9).toInt()
        }
    }
    return dialog
}